package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    //  /admin/product/baseCategoryTrademark/findTrademarkList/{category3Id}
    // 根据三级分类id获取品牌列表
    @GetMapping("/findTrademarkList/{category3Id}")
    public Result findTrademarkList(@PathVariable Long category3Id){
        //调用service服务层
        List<BaseTrademark> baseTrademarkList = baseCategoryTrademarkService.findTrademarkList(category3Id);

        // 返回结果
        return Result.ok(baseTrademarkList);
    }

    // /admin/product/baseCategoryTrademark/findCurrentTrademarkList/{category3Id}
    // 根据分类id 获取可选品牌列表
    @GetMapping("findCurrentTrademarkList/{category3Id}")
    public Result findCurrentTrademarkList(@PathVariable Long category3Id){

        //调用服务层
        List<BaseTrademark> baseTrademarkList = baseCategoryTrademarkService.findCurrentTrademarkList(category3Id);

        //返回信息
        return Result.ok(baseTrademarkList);
    }

    // /admin/product/baseCategoryTrademark/save
    //  保存分类关联
    @PostMapping("save")
    public Result save(@RequestBody CategoryTrademarkVo categoryTrademarkVo){

        //调用服务层添加方法
        baseCategoryTrademarkService.save(categoryTrademarkVo);

        //返回结果
        return Result.ok();

    }

    // /admin/product/baseCategoryTrademark/remove/{category3Id}/{trademarkId}
    // 删除分类与品牌关联
    @DeleteMapping("remove/{category3Id}/{trademarkId}")
    public Result remove(@PathVariable Long category3Id , @PathVariable Long trademarkId){

        // 调用服务层进行删除
        baseCategoryTrademarkService.remove(category3Id,trademarkId);
        //返回结果
        return Result.ok();

    }

}
